<template>
  <div class="register-container">
    <div class="container" style="width: 550px;height: 400px;padding: 20px;background-color: rgba(255, 255, 255, 0.2);
    border-radius: 5px;display: flex;flex-direction: column;justify-content: center;align-items: center;
    box-shadow: 2px 2px 10px rgba(255, 255, 255, 0.1),4px 4px 20px white,inset 1px 1px 2px wheat;backdrop-filter: blur(6px);">
      <div style="width: 100%; height: 100px; font-size: 30px; line-height: 100px; text-align: center; color: #4a5ed0">欢迎注册</div>
      <div style="margin-top: 10px; text-align: center; height: 320px;">
        <el-form :model="admin">
          <el-form-item>
            <el-input size="medium" v-model="admin.name" prefix-icon="el-icon-user" style="border-radius: 15px;width: 100%" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input size="medium" v-model="admin.password" show-password prefix-icon="el-icon-lock" style="border-radius: 15px;width: 100%" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-select v-model="admin.role" placeholder="请选择" style="width: 100%">
              <el-option label="教师" value="ROLE_TEACHER"></el-option>
              <el-option label="学生" value="ROLE_STUDENT"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button style="width: 80%; margin-top: 10px" type="primary" @click="register()">注册</el-button>
          </el-form-item>
          <div style="text-align: center">
            已有账号？<a href="javascript:void(0)" style="text-decoration: none" @click="navLogin">点击登录</a>
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>

import request from "@/utils/request";

export default {
  name: "Register",
  data() {
    return {
      admin: {}
    }
  },
  // 页面加载的时候，做一些事情，在created里面
  created() {
  },
  // 定义一些页面上控件出发的事件调用的方法
  methods: {
    register() {
      request.post("/admin/register", this.admin).then(res => {
        if (res.code === '0') {
          this.$message({
            message: '注册成功',
            type: 'success'
          });
          this.$router.push("/login");
        } else {
          this.$message({
            message: res.msg,
            type: 'error'
          });
        }
      })
    },
    navLogin() {
      this.$router.push("/login")
    }
  }
}
</script>

<style scoped>
/* register.css */
.register-container {
  background-color: #f2f2f2;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-image: url("@/assets/background2.jpg");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

</style>